<template>
  <div class="custom-title-bar">
    <!-- 标题栏左侧内容 -->
    <div class="title-bar-left">
      <span class="app-name">{{ store.param.title }}</span>
    </div>

    <!-- 标题栏右侧按钮 -->
    <div class="title-bar-right">
      <button class="title-bar-button" @click="minimize_window">
        <span class="iconfont icon-min"></span>
      </button>
      <button class="title-bar-button" @click="maximize_window">
        <span v-if="flag" class="iconfont icon-zuidahua"></span>
        <span
          v-else
          class="iconfont icon-liebiaoye-fuxuankuang-weixuanze"
        ></span>
      </button>
      <button class="title-bar-button close-button" @click="close_window">
        <span class="iconfont icon-chacha-copy"></span>
      </button>
    </div>
  </div>
</template>

<script setup>
import { Events } from "@/utils/events_bus/index.js";
import { ref } from "vue";
import { useIndexStore } from "@/store/model";

const store = useIndexStore()

const flag = ref(false);
// const title = ref("工具集")

// 最小化窗口
const minimize_window = () => {
  Events.IPC.Renderer.send("minimize-window");
};

// 最大化/还原窗口
const maximize_window = () => {
  console.log("最大化/还原窗口");
  Events.IPC.Renderer.send("maximize-window");
};

// 关闭窗口
const close_window = () => {
  Events.IPC.Renderer.send("close-window");
};

Events.IPC.Renderer.on("window-maximized", (e, params) => {
  flag.value = params;
});

// Events.IPC.Renderer.on("send_title", (e, params) => {
//   title.value = params;
// });

// const minimize = (e) => {
//   if
//   maximize_window()
// };
</script>

<style scoped lang="less">
.custom-title-bar {
  display: flex;
  justify-content: space-between;
  height: var(--title-height);
  box-sizing: border-box;
  border-bottom: var(--split-line);
  background-image: var(--title-bg);
  transition: 0.8s;
  background-size: 200% auto;
  -webkit-app-region: drag; /* 允许拖动 */
  color: var(--title-color);
  &:hover {
    background-position: right center; /* change the direction of the change here */
  }
  .title-bar-left {
    display: flex;
    align-items: center;
    margin-left: 10px;
    .app-name {
      font-size: 20px;
      font-weight: bold;
    }
  }
  .title-bar-right {
    // flex: 1;
    display: flex;
    align-items: center;
    // justify-content: end;
    -webkit-app-region: no-drag; /* 禁止拖动 */

    .title-bar-button {
      background: none;
      border: none;
      color: var(--title-icon-color);
      font-size: 16px;
      font-weight: 700;
      cursor: pointer;
      width: var(--title-height);
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      &:hover {
        background-color: var(--min-max-hover-color);
      }
    }
    .close-button:hover {
      background-color: var(--close-hover-color);
    }
  }
}
</style>
